package com.zr.action;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;
import com.zr.service.VanService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@Scope(value="prototype")
public class VanAction extends ActionSupport implements  ServletResponseAware{
	//接收页面数据展示传入的值
	private int page;
	private int rows;
	//接收增加功能表单传入的值
	private int car_status;
	private String car_type;
	//接收编辑功能传入的值
	private int id;	
	//接收删除功能传入的值
	private String ids;
	private HttpServletRequest request;
	private  HttpServletResponse  resp;
	
	public String getIds() {
		return ids;
	}
	public void setIds(String ids) {
		this.ids = ids;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getCar_status() {
		return car_status;
	}
	public void setCar_status(int car_status) {
		this.car_status = car_status;
	}
	public String getCar_type() {
		return car_type;
	}
	public void setCar_type(String car_type) {
		this.car_type = car_type;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.resp = response;
	}
	@Resource
	private VanService vanService;
	//页面数据展示
	public void showVan(){
		
		JSONObject  obj = vanService.showVan(page, rows);
		resp.setCharacterEncoding("utf8");
		try {
			resp.getWriter().write(obj.toString());
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//增加车辆功能
	public void addVan(){
		
		boolean flag=false;
		
			flag=vanService.addVan(car_type, car_status);
			try {
				resp.getWriter().write(String.valueOf(flag));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		
	}
	//编辑车辆功能
	public void updateVan(){
		boolean flag=false;
		
		flag=vanService.updateVan(car_type, car_status, id);
		try {
			resp.getWriter().write(String.valueOf(flag));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	//删除车辆功能
	public void destroyVan(){	
		String[] s =ids.split(",");
		boolean flag=false;
		flag=vanService.deleteVan(s);
		try {
			resp.getWriter().write(String.valueOf(flag));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
